#pragma once

#include <sys/epoll.h>

class EpollGuard {
private:
    int _epollFd;
    int _fd;
    epoll_event _event;

public:
    EpollGuard(int efd, int fd) : _epollFd(efd), _fd(fd) {
        _event.data.fd = _fd;
        _event.events = EPOLLIN | EPOLLET;
        epoll_ctl(_epollFd, EPOLL_CTL_ADD, _event.data.fd, &_event);
    }

    ~EpollGuard() { epoll_ctl(_epollFd, EPOLL_CTL_DEL, _fd, nullptr); }

    epoll_event *event() { return &_event; }
};
